﻿$(document).ready(function () {





   



    $('.recommendtype').change(function () {
        var _type = $(this).val();
        var _oppgender = $('#oppgender').attr('data');
        var _descending = $('#descending').attr('data');
        var _currentpage = 1;
        AjaxRecommendList(_currentpage, _type, _oppgender, _descending);

    });

    $('#oppgender').click(function () {
        var _type = $('.recommendtype').val();
        $('#oppgender').attr("data", ($('#oppgender').attr('data')) == true ? false : true);
        var _oppgender = $('#oppgender').attr('data');
        var _descending = $('#descending').attr('data');
        var _currentpage = 1;
        AjaxRecommendList(_currentpage, _type, _oppgender, _descending);
    });

    $('#descending').click(function () {
        var _type = $('.recommendtype').val();
        $('#descending').attr("data", ($('#descending').attr('data')) == true ? false : true);
        var _oppgender = $('#oppgender').attr('data');
        var _descending = $('#descending').attr('data');
        var _currentpage = 1;
        AjaxRecommendList(_currentpage, _type, _oppgender, _descending);
    });



    function AjaxRecommendList(_currentpage, _type, _oppgender, _descending) {
        $.ajax({
            type: 'POST',
            url: "http://" + window.location.host + "/Json/RecommendJson",
            data: { currentpage: _currentpage, type: _type, isOppGender: _oppgender, isDescending: _descending },
            success: function (data) {
                for (i = 0; i < data.length; i++) {
                    var _imagepath = data[i].ImagePath;
                    var _truename = data[i].TrueName;
                    var _address = data[i].Address;
                    var _uniaddress = data[i].UniAddress;
                    var _gender = data[i].Gender;
                    var _majorclass = data[i].MajorClass;
                    var _schoolyear = data[i].SchoolYear;
                    var _hobbies = data[i].Hobbies;
                    var _userid = data[i].UserId;
                    alert(_imagepath + _truename + _address + _uniaddress + _gender + _majorclass + _schoolyear + _hobbies + _userid);
                    ///change the UI
                }

            },
            error: function () {
                alert('posterror');
            }
        });

    }

});
